﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ComponentModel;
using KNXObjects.Enum;
using KNXObjects.Addresses;

namespace KNXObjects
{
    public abstract class GenericObjectBase<TValue> : ObjectBase, IEquatable<TValue> 
        where TValue : new()
    {
        public GenericObjectBase(string id, string address, string name, string flags) : base(id, address, name, flags)
        {}
        public GenericObjectBase() : base()
        {}
        #region IEquatable<TValue> Members

        public bool Equals(TValue other)
        {
            return Value.Equals(other);
        }

        #endregion

        #region Fields

        TValue m_Value;

        public virtual TValue Value
        {
            get {
                if (m_Value == null)
                    m_Value = new TValue();

                if (base.Value == null || !((TValue)base.Value).Equals(m_Value))
                    base.Value = m_Value;
                return m_Value; 
            }
            set {
                if (m_Value == null || !m_Value.Equals(value))
                {
                    m_Value = value;                    
                    NotifyPropertyChanged("Value");
                }
                base.Value = m_Value;
            }
        }

        #endregion


    }
}
